<?php

namespace App\Http\Middleware;

use Closure;
use Nette\Mail\Message;
use Nette\Mail\SmtpMailer;
class EmailMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        //echo 123;exit;
        $res = $next($request);
       // print_r($request->user());exit;
        if($request->user()){
            $mail = new Message;
            $mail->setFrom('薛松 <ox8888xo@163.com>')
                ->addTo($request->user()->email)
                ->setSubject('标题这是 试试我的中间件')
                ->setBody("这是内容,试试我的中间件内容.");
        
           $mailer = new SmtpMailer([
            'host' => 'smtp.163.com',
            'username' => 'ox8888xo',
            'password' => '******',
            ]);
            $mailer->send($mail);
        
        
         }
     return $res;
    }
}
